package org.ne.springboot.utils;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wey
 * @date 2025/8/31 下午7:06 08
 **/
public class YamlUtils {
    private static Map<String, Object> getConfigInfo(String fileName) {
        Yaml yaml = new Yaml(new Constructor(Map.class));
        Map<String, Object> config = new HashMap<>();
        try (InputStream inputStream = YamlUtils.class.getClassLoader().getResourceAsStream(fileName)) {
            // 加载 YAML 文件
            config = yaml.load(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return config;
    }


    private static final Map<String, Object> config = getConfigInfo("application-dev.yml");

    public static Map<String, Object> getInfo(String fileName) {
        return (Map<String, Object>) config.get(fileName);
    }
}
